﻿//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Data.SqlClient;
using NetCMS.DALFactory;
using NetCMS.Model;
using NetCMS.Common;
using System.Text.RegularExpressions;
using System.Text;
using System.Reflection;
using NetCMS.DALProfile;
using NetCMS.Config;

namespace NetCMS.DALSQLServer
{
    public class Arealist : DbBase, IArealist
    {
        #region arealist.aspx
        public DataTable sel_sysCity(string Cid,bool flag)
        {
            #region
            string Sql = null;
            SqlParameter param = new SqlParameter("@Cid",Cid);
            if (flag)
            {
                Sql = "Select Cid,cityName,creatTime From " + Pre + "Sys_City Where Pid=@Cid and SiteID='" + NetCMS.Global.Current.SiteID + "' order by OrderID desc,id desc";
            }
            else
            {
                Sql = "select cityName,OrderID,Pid from " + Pre + "Sys_City where Cid=@Cid and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            }
            return DbHelper.ExecuteTable(CommandType.Text, Sql, param);
            #endregion
        }

        public DataTable sel_sysCityInfo(int flag)
        {
            #region
            string Sql = null;
            if (flag==0)
            {
                Sql = "select Cid,cityName,Pid from " + Pre + "Sys_City where SiteID='" + NetCMS.Global.Current.SiteID + "'";
            }
            else if(flag==1)
            {
                Sql = "select Cid,cityName from " + Pre + "Sys_City where Pid='0' and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            }
            else if (flag == 2)
            {
                Sql = "select Cid from " + Pre + "Sys_City";
            }
            return DbHelper.ExecuteTable(CommandType.Text, Sql, null);
            #endregion
        }

        public int del_sysCity(string ID,int flag)
        {
            #region
            string Sql = null;
            if (flag == 0)
            {
                Sql = "delete " + Pre + "Sys_City where (Cid='" + ID + "'and Pid='0') or Pid='" + ID + "' and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            }
            else if (flag == 1)
            {
                Sql = "delete " + Pre + "Sys_City where  Cid='" + ID + "' and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            }
            else if (flag == 2)
            {
                Sql = "delete " + Pre + "Sys_City where Cid='" + ID + "'";
            }
            return DbHelper.ExecuteNonQuery(CommandType.Text, Sql, null);
            #endregion
        }

        #endregion

        #region arealist_add.aspx
        public int Add(string Cid, string cityName, DateTime creatTime, int orderID)
        {
            string Sql = "insert into " + Pre + "Sys_City(Cid,cityName,Pid,creatTime,SiteID,orderID) values('" + Cid + "','" + cityName + "','0','" + creatTime + "','" + NetCMS.Global.Current.SiteID + "'," + orderID + ")";
            return DbHelper.ExecuteNonQuery(CommandType.Text, Sql, null);
        }
        public int sel_nameTF(string aName)
        {
            int intflg = 0;
            SqlParameter param = new SqlParameter("@Name",aName);
            string Sql = "select id from " + Pre + "Sys_City where cityName=@Name";
            DataTable dt = DbHelper.ExecuteTable(CommandType.Text, Sql, param);
            if (dt != null)
            {
                if (dt.Rows.Count > 0) { intflg = 1; }
                dt.Clear(); dt.Dispose();
            }
            return intflg;
        }
        #endregion

        #region Arealist.cs
        public int add_sysCity(string Pid, string Cid, string cityName, DateTime creatTime, int orderID)
        {
            string Sql = "insert into " + Pre + "Sys_City(Pid,Cid,cityName,creatTime,SiteID,orderID) values('" + Pid + "','" + Cid + "','" + cityName + "','" + creatTime + "','" + NetCMS.Global.Current.SiteID + "'," + orderID + ")";
            return DbHelper.ExecuteNonQuery(CommandType.Text, Sql, null);
        }
        #endregion

        #region arealist_upc.aspx
        public int Update(string Pid, string cityName, DateTime creatTime, string cids, int OrderID)
        {
            SqlParameter[] param = new SqlParameter[5];
            param[0] = new SqlParameter("@Pid", SqlDbType.NVarChar,12);
            param[0].Value = Pid;
            param[1] = new SqlParameter("@cityName", SqlDbType.NVarChar,30);
            param[1].Value = cityName;
            param[2] = new SqlParameter("@creatTime", SqlDbType.DateTime, 8);
            param[2].Value = creatTime;
            param[3] = new SqlParameter("@cids", SqlDbType.NVarChar, 12);
            param[3].Value = cids;
            param[4] = new SqlParameter("@OrderID", SqlDbType.Int,4);
            param[4].Value = OrderID;
            string Sql = "update " + Pre + "Sys_City set Pid=@Pid,cityName=@cityName,creatTime=@creatTime,OrderID=@OrderID where Cid=@cids and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            return DbHelper.ExecuteNonQuery(CommandType.Text, Sql, param);
        }
        #endregion

        #region arealist_upp.aspx
        public int Update_sysCity(string cityName, DateTime creatTime, string Cids, int orderID)
        {
            SqlParameter[] param = new SqlParameter[4];
            param[0] = new SqlParameter("@cityName", SqlDbType.NVarChar, 30);
            param[0].Value = cityName;
            param[1] = new SqlParameter("@creatTime", SqlDbType.DateTime, 8);
            param[1].Value = creatTime;
            param[2] = new SqlParameter("@Cids", SqlDbType.NVarChar, 12);
            param[2].Value = Cids;
            param[3] = new SqlParameter("@orderID", SqlDbType.Int, 4);
            param[3].Value = orderID;
            string Sql = "update " + Pre + "Sys_City set cityName=@cityName,creatTime=@creatTime,orderID=@orderID where Cid=@Cids and SiteID='" + NetCMS.Global.Current.SiteID + "'";
            return DbHelper.ExecuteNonQuery(CommandType.Text, Sql, param);
        }
        #endregion
    }
}